package com.code.leetcode.idea;

public class LeetCodeIdea009 {
    public static void main(String[] args) {
        LeetCodeIdea009 leetCodeIdea009 = new LeetCodeIdea009();
        boolean res = leetCodeIdea009.isPalindrome(121);
        System.out.println(res);

    }
    public boolean judge (char[] arr, int left, int right) {
        while (left >=0 && right <arr.length && arr[left] == arr[right]) {
            left--;
            right++;
        }
        if (left < 0) {
            return true;
        }
        return false;

    }
    public boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }
        if (x < 10) {
            return true;
        }
        String xStr = String.valueOf(x);
        char[] arr = xStr.toCharArray();
        int len = xStr.length();
        int mid = len /2;
        if ( len % 2 ==0 ) {
            return judge(arr, mid-1, mid);
        } else {
            return judge(arr, mid-1, mid+1);
        }
    }
}
